/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cluelessserver;

/**
 *
 * @author dcain
 */
public class Board {
    BoardSpace[] rooms = new BoardSpace [27];
    
    BoardSpace getRoom(int index){
        return rooms[index];
    }
    /**
     * Returns a room based on its name.
     * @param roomName name of the room to find
     * @return room with the specified name
     */
    public BoardSpace getRoom(String roomName){
        int i = 0;
        BoardSpace result = rooms[i];
        while (!(result.name.startsWith(roomName)) && i < 25){
            result = rooms[++i];
        }
        result = rooms[i];        
        return result;
    }
    /**
     * Constructor builds the board from board spaces and then links them together.
     */
    Board(){        
        String[] roomList = {"Study", "Hall", "Lounge", "Library", "Billiard_Room", "Dining_Room", "Conservatory", "Ballroom", "Kitchen", 
        "ScarletStart","PlumStart","MustardStart","PeacockStart", "GreenStart","WhiteStart"};
        String[] hallList = {"Study_Hall", "Hall_Lounge", "Study_Library", "Hall_Billiard", 
        "Lounge_Dining", "Library_Billiard", "Billiard_Dining", "Library_Conservatory", 
        "Billiard_Ballroom", "Dining_Kitchen", "Conservatory_Ballroom", "Ballroom_Kitchen"};
        for (int i = 0; i < 15; i++){        
            rooms[i] = new Room(roomList[i]);              
        }
        for (int i = 15; i < 27; i++){ 
            rooms[i] = new Hall(hallList[i-15]);            
        }
        
        //connections are: North, South, West, East, Secret        
        //Study
        rooms[0].makeConnections(null, rooms[17], null, rooms[15], rooms[8]);
        //Hall
        rooms[1].makeConnections(null, rooms[18], rooms[15], rooms[16], null);
        //Lounge
        rooms[2].makeConnections(null, rooms[19], rooms[16], null, rooms[6]);
        //Library
        rooms[3].makeConnections(rooms[17], rooms[22], null, rooms[20], null);
        //Billiard
        rooms[4].makeConnections(rooms[18], rooms[23], rooms[20], rooms[21], null);
        //Dining
        rooms[5].makeConnections(rooms[19],rooms[24],rooms[21],null,null);
        //Conservatory
        rooms[6].makeConnections(rooms[22], null, null, rooms[25], null);
        //Ballroom
        rooms[7].makeConnections(rooms[23], null, rooms[25], rooms[26], null);
        //Kitchen
        rooms[8].makeConnections(rooms[24], null, rooms[26], null, rooms[0]);
        //ScarletStart
        rooms[9].makeConnections(null, rooms[16], null, null, null);
        //Plum
        rooms[10].makeConnections(null, null, null, rooms[17], null);
        //Mustard
        rooms[11].makeConnections(null, null, rooms[19], null, null);
        //Peacock
        rooms[12].makeConnections(null, null, null, rooms[22], null);
        //Green
        rooms[13].makeConnections(rooms[25], null, null, null, null);
        //White
        rooms[14].makeConnections(rooms[26], null, null, null, null);
        //StdHall
        rooms[15].makeConnections(null, null, rooms[0], rooms[1], null);
        //HallLounge
        rooms[16].makeConnections(null, null, rooms[1], rooms[2], null);
        //StdLib
        rooms[17].makeConnections(rooms[0], rooms[3], null, null, null);
        //HallBill
        rooms[18].makeConnections(rooms[1], rooms[4], null, null, null);
        //LoungeDining
        rooms[19].makeConnections(rooms[2], rooms[5], null, null, null);
        //LibBill
        rooms[20].makeConnections(null, null,rooms[3], rooms[4], null);
        //BillDining
        rooms[21].makeConnections(null, null,rooms[4], rooms[5], null);
        //LibCon
        rooms[22].makeConnections(rooms[3],rooms[6],null, null, null);
        //BillBall
        rooms[23].makeConnections(rooms[4],rooms[7],null, null, null);
        //DinKit
        rooms[24].makeConnections(rooms[5],rooms[8],null, null, null);
        //ConBall
        rooms[25].makeConnections(null, null,rooms[6], rooms[7], null);
        //BallKitchen
        rooms[26].makeConnections(null, null,rooms[7], rooms[8], null);
    }
}
